import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';

class SecondController extends GetxController {
  final filters = [
    Colors.white,
    ...List.generate(
      Colors.primaries.length,
      (index) => Colors.primaries[(index * 4) % Colors.primaries.length],
    )
  ];
  final lightBtnState = false.obs;
  final imgPathObs = "".obs;

  final ImagePicker picker = ImagePicker();

  final filterColor = Colors.white.obs;

  void onFilterChanged(Color value) {
    filterColor.value = value;
  }

  chooseCamera() async {
    final XFile? image = await picker.pickImage(
      source: ImageSource.camera,
    );
    imgPathObs.value = image?.path ?? "";
  }

  chooseLibray() async {
    final XFile? image = await picker.pickImage(
      source: ImageSource.gallery,
    );
    imgPathObs.value = image?.path ?? "";
  }

  changeLightBtnState() {
    lightBtnState.value = !lightBtnState.value;
  }

  reloadPic() {
    imgPathObs.value = "";
  }

  @override
  void dispose() {
    lightBtnState.close();
    imgPathObs.close();
    super.dispose();
  }
}
